<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Coverage for c:\program files\python26\lib\socket</title>
<link rel='stylesheet' href='style.css' type='text/css'>
<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
<script type='text/javascript'>
function toggle_lines(btn, cls) {
    var btn = $(btn);
    var hide = "hide_"+cls;
    if (btn.hasClass(hide)) {
        $("#source ."+cls).removeClass(hide);
        btn.removeClass(hide);
    }
    else {
        $("#source ."+cls).addClass(hide);
        btn.addClass(hide);
    }
}
</script>
</head>
<body>
<div id='header'>
    <div class='content'>
        <h1>Coverage for <b>c:\program files\python26\lib\socket</b> :
            <span class='pc_cov'>4%</span>
        </h1>
        <h2 class='stats'>
            302 statements
            <span class='run hide_run' onclick='toggle_lines(this, "run")'>11 run</span>
            <span class='exc' onclick='toggle_lines(this, "exc")'>0 excluded</span>
            <span class='mis' onclick='toggle_lines(this, "mis")'>291 missing</span>
            
                <span class='par run hide_run' onclick='toggle_lines(this, "par")'>0 partial</span>
            
        </h2>
    </div>
</div>

<div id='source'>
<table cellspacing='0' cellpadding='0'>
<tr>
<td class='linenos' valign='top'>
<p class='pln'>1</p>
<p class='pln'>2</p>
<p class='pln'>3</p>
<p class='stm mis'>4</p>
<p class='pln'>5</p>
<p class='pln'>6</p>
<p class='pln'>7</p>
<p class='pln'>8</p>
<p class='pln'>9</p>
<p class='pln'>10</p>
<p class='pln'>11</p>
<p class='pln'>12</p>
<p class='pln'>13</p>
<p class='pln'>14</p>
<p class='pln'>15</p>
<p class='pln'>16</p>
<p class='pln'>17</p>
<p class='pln'>18</p>
<p class='pln'>19</p>
<p class='pln'>20</p>
<p class='pln'>21</p>
<p class='pln'>22</p>
<p class='pln'>23</p>
<p class='pln'>24</p>
<p class='pln'>25</p>
<p class='pln'>26</p>
<p class='pln'>27</p>
<p class='pln'>28</p>
<p class='pln'>29</p>
<p class='pln'>30</p>
<p class='pln'>31</p>
<p class='pln'>32</p>
<p class='pln'>33</p>
<p class='pln'>34</p>
<p class='pln'>35</p>
<p class='pln'>36</p>
<p class='pln'>37</p>
<p class='pln'>38</p>
<p class='pln'>39</p>
<p class='pln'>40</p>
<p class='pln'>41</p>
<p class='pln'>42</p>
<p class='pln'>43</p>
<p class='pln'>44</p>
<p class='pln'>45</p>
<p class='stm mis'>46</p>
<p class='stm mis'>47</p>
<p class='pln'>48</p>
<p class='stm mis'>49</p>
<p class='stm mis'>50</p>
<p class='stm mis'>51</p>
<p class='pln'>52</p>
<p class='stm mis'>53</p>
<p class='pln'>54</p>
<p class='stm mis'>55</p>
<p class='pln'>56</p>
<p class='pln'>57</p>
<p class='stm mis'>58</p>
<p class='stm mis'>59</p>
<p class='pln'>60</p>
<p class='stm mis'>61</p>
<p class='pln'>62</p>
<p class='pln'>63</p>
<p class='stm mis'>64</p>
<p class='stm mis'>65</p>
<p class='pln'>66</p>
<p class='pln'>67</p>
<p class='pln'>68</p>
<p class='pln'>69</p>
<p class='pln'>70</p>
<p class='pln'>71</p>
<p class='pln'>72</p>
<p class='pln'>73</p>
<p class='pln'>74</p>
<p class='pln'>75</p>
<p class='pln'>76</p>
<p class='pln'>77</p>
<p class='pln'>78</p>
<p class='stm mis'>79</p>
<p class='pln'>80</p>
<p class='stm mis'>81</p>
<p class='stm mis'>82</p>
<p class='stm mis'>83</p>
<p class='stm mis'>84</p>
<p class='pln'>85</p>
<p class='stm mis'>86</p>
<p class='stm mis'>87</p>
<p class='stm mis'>88</p>
<p class='stm mis'>89</p>
<p class='pln'>90</p>
<p class='stm mis'>91</p>
<p class='stm mis'>92</p>
<p class='pln'>93</p>
<p class='pln'>94</p>
<p class='stm mis'>95</p>
<p class='pln'>96</p>
<p class='pln'>97</p>
<p class='stm mis'>98</p>
<p class='stm mis'>99</p>
<p class='stm mis'>100</p>
<p class='stm mis'>101</p>
<p class='stm mis'>102</p>
<p class='stm mis'>103</p>
<p class='stm mis'>104</p>
<p class='stm mis'>105</p>
<p class='stm mis'>106</p>
<p class='stm mis'>107</p>
<p class='stm mis'>108</p>
<p class='stm mis'>109</p>
<p class='stm mis'>110</p>
<p class='stm mis'>111</p>
<p class='stm mis'>112</p>
<p class='stm mis'>113</p>
<p class='stm mis'>114</p>
<p class='stm mis'>115</p>
<p class='pln'>116</p>
<p class='pln'>117</p>
<p class='pln'>118</p>
<p class='stm mis'>119</p>
<p class='pln'>120</p>
<p class='pln'>121</p>
<p class='pln'>122</p>
<p class='pln'>123</p>
<p class='pln'>124</p>
<p class='pln'>125</p>
<p class='pln'>126</p>
<p class='pln'>127</p>
<p class='stm mis'>128</p>
<p class='stm mis'>129</p>
<p class='stm mis'>130</p>
<p class='stm mis'>131</p>
<p class='stm mis'>132</p>
<p class='stm mis'>133</p>
<p class='stm mis'>134</p>
<p class='pln'>135</p>
<p class='stm mis'>136</p>
<p class='stm mis'>137</p>
<p class='stm mis'>138</p>
<p class='stm mis'>139</p>
<p class='pln'>140</p>
<p class='stm mis'>141</p>
<p class='stm mis'>142</p>
<p class='pln'>143</p>
<p class='pln'>144</p>
<p class='stm mis'>145</p>
<p class='pln'>146</p>
<p class='pln'>147</p>
<p class='pln'>148</p>
<p class='pln'>149</p>
<p class='pln'>150</p>
<p class='stm mis'>151</p>
<p class='stm mis'>152</p>
<p class='pln'>153</p>
<p class='stm mis'>154</p>
<p class='stm mis'>155</p>
<p class='pln'>156</p>
<p class='pln'>157</p>
<p class='pln'>158</p>
<p class='stm mis'>159</p>
<p class='pln'>160</p>
<p class='pln'>161</p>
<p class='stm mis'>162</p>
<p class='stm mis'>163</p>
<p class='stm mis'>164</p>
<p class='stm mis'>165</p>
<p class='pln'>166</p>
<p class='stm mis'>167</p>
<p class='stm mis'>168</p>
<p class='pln'>169</p>
<p class='pln'>170</p>
<p class='pln'>171</p>
<p class='pln'>172</p>
<p class='pln'>173</p>
<p class='stm mis'>174</p>
<p class='pln'>175</p>
<p class='stm mis'>176</p>
<p class='pln'>177</p>
<p class='stm mis'>178</p>
<p class='pln'>179</p>
<p class='stm mis'>180</p>
<p class='stm run hide_run'>181</p>
<p class='stm run hide_run'>182</p>
<p class='stm run hide_run'>183</p>
<p class='stm run hide_run'>184</p>
<p class='stm run hide_run'>185</p>
<p class='pln'>186</p>
<p class='stm mis'>187</p>
<p class='stm run hide_run'>188</p>
<p class='stm run hide_run'>189</p>
<p class='stm run hide_run'>190</p>
<p class='stm run hide_run'>191</p>
<p class='stm mis'>192</p>
<p class='pln'>193</p>
<p class='stm mis'>194</p>
<p class='stm run hide_run'>195</p>
<p class='stm run hide_run'>196</p>
<p class='stm mis'>197</p>
<p class='pln'>198</p>
<p class='stm mis'>199</p>
<p class='pln'>200</p>
<p class='pln'>201</p>
<p class='pln'>202</p>
<p class='stm mis'>203</p>
<p class='pln'>204</p>
<p class='stm mis'>205</p>
<p class='pln'>206</p>
<p class='pln'>207</p>
<p class='pln'>208</p>
<p class='pln'>209</p>
<p class='stm mis'>210</p>
<p class='pln'>211</p>
<p class='stm mis'>212</p>
<p class='stm mis'>213</p>
<p class='stm mis'>214</p>
<p class='pln'>215</p>
<p class='stm mis'>216</p>
<p class='pln'>217</p>
<p class='stm mis'>218</p>
<p class='stm mis'>219</p>
<p class='stm mis'>220</p>
<p class='pln'>221</p>
<p class='stm mis'>222</p>
<p class='pln'>223</p>
<p class='stm mis'>224</p>
<p class='pln'>225</p>
<p class='pln'>226</p>
<p class='stm mis'>227</p>
<p class='stm mis'>228</p>
<p class='pln'>229</p>
<p class='stm mis'>230</p>
<p class='pln'>231</p>
<p class='pln'>232</p>
<p class='pln'>233</p>
<p class='pln'>234</p>
<p class='stm mis'>235</p>
<p class='stm mis'>236</p>
<p class='stm mis'>237</p>
<p class='stm mis'>238</p>
<p class='stm mis'>239</p>
<p class='stm mis'>240</p>
<p class='stm mis'>241</p>
<p class='pln'>242</p>
<p class='pln'>243</p>
<p class='pln'>244</p>
<p class='stm mis'>245</p>
<p class='stm mis'>246</p>
<p class='stm mis'>247</p>
<p class='stm mis'>248</p>
<p class='pln'>249</p>
<p class='stm mis'>250</p>
<p class='stm mis'>251</p>
<p class='pln'>252</p>
<p class='pln'>253</p>
<p class='pln'>254</p>
<p class='pln'>255</p>
<p class='stm mis'>256</p>
<p class='stm mis'>257</p>
<p class='stm mis'>258</p>
<p class='pln'>259</p>
<p class='stm mis'>260</p>
<p class='stm mis'>261</p>
<p class='stm mis'>262</p>
<p class='pln'>263</p>
<p class='stm mis'>264</p>
<p class='stm mis'>265</p>
<p class='stm mis'>266</p>
<p class='stm mis'>267</p>
<p class='pln'>268</p>
<p class='stm mis'>269</p>
<p class='stm mis'>270</p>
<p class='stm mis'>271</p>
<p class='pln'>272</p>
<p class='stm mis'>273</p>
<p class='stm mis'>274</p>
<p class='stm mis'>275</p>
<p class='stm mis'>276</p>
<p class='pln'>277</p>
<p class='stm mis'>278</p>
<p class='pln'>279</p>
<p class='stm mis'>280</p>
<p class='stm mis'>281</p>
<p class='stm mis'>282</p>
<p class='stm mis'>283</p>
<p class='stm mis'>284</p>
<p class='pln'>285</p>
<p class='stm mis'>286</p>
<p class='stm mis'>287</p>
<p class='pln'>288</p>
<p class='stm mis'>289</p>
<p class='stm mis'>290</p>
<p class='stm mis'>291</p>
<p class='stm mis'>292</p>
<p class='stm mis'>293</p>
<p class='stm mis'>294</p>
<p class='pln'>295</p>
<p class='pln'>296</p>
<p class='stm mis'>297</p>
<p class='pln'>298</p>
<p class='stm mis'>299</p>
<p class='pln'>300</p>
<p class='pln'>301</p>
<p class='stm mis'>302</p>
<p class='stm mis'>303</p>
<p class='pln'>304</p>
<p class='stm mis'>305</p>
<p class='pln'>306</p>
<p class='stm mis'>307</p>
<p class='stm mis'>308</p>
<p class='stm mis'>309</p>
<p class='stm mis'>310</p>
<p class='stm mis'>311</p>
<p class='pln'>312</p>
<p class='stm mis'>313</p>
<p class='pln'>314</p>
<p class='pln'>315</p>
<p class='pln'>316</p>
<p class='stm mis'>317</p>
<p class='pln'>318</p>
<p class='pln'>319</p>
<p class='pln'>320</p>
<p class='stm mis'>321</p>
<p class='stm mis'>322</p>
<p class='stm mis'>323</p>
<p class='pln'>324</p>
<p class='stm mis'>325</p>
<p class='stm mis'>326</p>
<p class='stm mis'>327</p>
<p class='stm mis'>328</p>
<p class='stm mis'>329</p>
<p class='stm mis'>330</p>
<p class='stm mis'>331</p>
<p class='pln'>332</p>
<p class='pln'>333</p>
<p class='stm mis'>334</p>
<p class='stm mis'>335</p>
<p class='pln'>336</p>
<p class='stm mis'>337</p>
<p class='stm mis'>338</p>
<p class='stm mis'>339</p>
<p class='stm mis'>340</p>
<p class='stm mis'>341</p>
<p class='pln'>342</p>
<p class='stm mis'>343</p>
<p class='stm mis'>344</p>
<p class='stm mis'>345</p>
<p class='pln'>346</p>
<p class='pln'>347</p>
<p class='pln'>348</p>
<p class='pln'>349</p>
<p class='pln'>350</p>
<p class='stm mis'>351</p>
<p class='stm mis'>352</p>
<p class='stm mis'>353</p>
<p class='stm mis'>354</p>
<p class='stm mis'>355</p>
<p class='pln'>356</p>
<p class='pln'>357</p>
<p class='pln'>358</p>
<p class='pln'>359</p>
<p class='pln'>360</p>
<p class='stm mis'>361</p>
<p class='stm mis'>362</p>
<p class='stm mis'>363</p>
<p class='stm mis'>364</p>
<p class='stm mis'>365</p>
<p class='stm mis'>366</p>
<p class='stm mis'>367</p>
<p class='stm mis'>368</p>
<p class='stm mis'>369</p>
<p class='pln'>370</p>
<p class='stm mis'>371</p>
<p class='pln'>372</p>
<p class='stm mis'>373</p>
<p class='stm mis'>374</p>
<p class='stm mis'>375</p>
<p class='stm mis'>376</p>
<p class='pln'>377</p>
<p class='stm mis'>378</p>
<p class='stm mis'>379</p>
<p class='stm mis'>380</p>
<p class='stm mis'>381</p>
<p class='stm mis'>382</p>
<p class='stm mis'>383</p>
<p class='stm mis'>384</p>
<p class='stm mis'>385</p>
<p class='pln'>386</p>
<p class='stm mis'>387</p>
<p class='pln'>388</p>
<p class='stm mis'>389</p>
<p class='stm mis'>390</p>
<p class='stm mis'>391</p>
<p class='stm mis'>392</p>
<p class='stm mis'>393</p>
<p class='stm mis'>394</p>
<p class='stm mis'>395</p>
<p class='stm mis'>396</p>
<p class='stm mis'>397</p>
<p class='stm mis'>398</p>
<p class='stm mis'>399</p>
<p class='pln'>400</p>
<p class='stm mis'>401</p>
<p class='stm mis'>402</p>
<p class='stm mis'>403</p>
<p class='stm mis'>404</p>
<p class='stm mis'>405</p>
<p class='stm mis'>406</p>
<p class='stm mis'>407</p>
<p class='stm mis'>408</p>
<p class='stm mis'>409</p>
<p class='stm mis'>410</p>
<p class='stm mis'>411</p>
<p class='stm mis'>412</p>
<p class='stm mis'>413</p>
<p class='stm mis'>414</p>
<p class='stm mis'>415</p>
<p class='pln'>416</p>
<p class='pln'>417</p>
<p class='stm mis'>418</p>
<p class='stm mis'>419</p>
<p class='stm mis'>420</p>
<p class='stm mis'>421</p>
<p class='stm mis'>422</p>
<p class='stm mis'>423</p>
<p class='stm mis'>424</p>
<p class='stm mis'>425</p>
<p class='stm mis'>426</p>
<p class='stm mis'>427</p>
<p class='stm mis'>428</p>
<p class='stm mis'>429</p>
<p class='stm mis'>430</p>
<p class='stm mis'>431</p>
<p class='pln'>432</p>
<p class='stm mis'>433</p>
<p class='stm mis'>434</p>
<p class='stm mis'>435</p>
<p class='pln'>436</p>
<p class='stm mis'>437</p>
<p class='stm mis'>438</p>
<p class='stm mis'>439</p>
<p class='stm mis'>440</p>
<p class='pln'>441</p>
<p class='pln'>442</p>
<p class='pln'>443</p>
<p class='stm mis'>444</p>
<p class='stm mis'>445</p>
<p class='stm mis'>446</p>
<p class='pln'>447</p>
<p class='pln'>448</p>
<p class='stm mis'>449</p>
<p class='stm mis'>450</p>
<p class='stm mis'>451</p>
<p class='stm mis'>452</p>
<p class='stm mis'>453</p>
<p class='stm mis'>454</p>
<p class='stm mis'>455</p>
<p class='pln'>456</p>
<p class='stm mis'>457</p>
<p class='pln'>458</p>
<p class='stm mis'>459</p>
<p class='stm mis'>460</p>
<p class='stm mis'>461</p>
<p class='stm mis'>462</p>
<p class='stm mis'>463</p>
<p class='stm mis'>464</p>
<p class='stm mis'>465</p>
<p class='stm mis'>466</p>
<p class='stm mis'>467</p>
<p class='stm mis'>468</p>
<p class='stm mis'>469</p>
<p class='stm mis'>470</p>
<p class='pln'>471</p>
<p class='pln'>472</p>
<p class='pln'>473</p>
<p class='stm mis'>474</p>
<p class='stm mis'>475</p>
<p class='pln'>476</p>
<p class='stm mis'>477</p>
<p class='stm mis'>478</p>
<p class='stm mis'>479</p>
<p class='stm mis'>480</p>
<p class='stm mis'>481</p>
<p class='pln'>482</p>
<p class='stm mis'>483</p>
<p class='pln'>484</p>
<p class='stm mis'>485</p>
<p class='pln'>486</p>
<p class='pln'>487</p>
<p class='pln'>488</p>
<p class='pln'>489</p>
<p class='pln'>490</p>
<p class='pln'>491</p>
<p class='pln'>492</p>
<p class='pln'>493</p>
<p class='pln'>494</p>
<p class='pln'>495</p>
<p class='stm mis'>496</p>
<p class='stm mis'>497</p>
<p class='stm mis'>498</p>
<p class='stm mis'>499</p>
<p class='stm mis'>500</p>
<p class='stm mis'>501</p>
<p class='stm mis'>502</p>
<p class='stm mis'>503</p>
<p class='stm mis'>504</p>
<p class='stm mis'>505</p>
<p class='stm mis'>506</p>
<p class='pln'>507</p>
<p class='stm mis'>508</p>
<p class='stm mis'>509</p>
<p class='stm mis'>510</p>
<p class='pln'>511</p>
<p class='stm mis'>512</p>
    
</td>
<td class='text' valign='top'>
<p class='pln'><span class='com'># Wrapper module for _socket, providing some additional facilities</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># implemented in Python.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='str'>&quot;&quot;&quot;\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>This module provides socket operations and some related functions.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>On Unix, it supports IP (Internet Protocol) and Unix domain sockets.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>On other systems, it only supports IP. Functions specific for a</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>socket are available as methods of the socket object.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>Functions:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>socket() -- create a new socket object</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>socketpair() -- create a pair of new socket objects [*]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>fromfd() -- create a socket object from an open file descriptor [*]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>gethostname() -- return the current hostname</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>gethostbyname() -- map a hostname to its IP number</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>gethostbyaddr() -- map an IP number or hostname to DNS info</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>getservbyname() -- map a service name and a protocol name to a port number</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>getprotobyname() -- mape a protocol name (e.g. &#39;tcp&#39;) to a number</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>htons(), htonl() -- convert 16, 32 bit int from host to network byte order</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>ssl() -- secure socket layer support (only available if configured)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>socket.getdefaulttimeout() -- get the default timeout value</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>socket.setdefaulttimeout() -- set the default timeout value</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>create_connection() -- connects to an address, with an optional timeout</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> [*] not available on all platforms!</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>Special objects:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>SocketType -- type object for socket objects</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>error -- exception raised for I/O errors</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>has_ipv6 -- boolean value indicating if IPv6 is supported</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>Integer constants:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>AF_INET, AF_UNIX -- socket domains (first argument to socket() call)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>Many other constants may be defined; these may be used in calls to</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>the setsockopt() and getsockopt() methods.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>import</span> <span class='nam'>_socket</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>from</span> <span class='nam'>_socket</span> <span class='key'>import</span> <span class='op'>*</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>import</span> <span class='nam'>_ssl</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>except</span> <span class='nam'>ImportError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># no SSL support</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>ssl</span><span class='op'>(</span><span class='nam'>sock</span><span class='op'>,</span> <span class='nam'>keyfile</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>,</span> <span class='nam'>certfile</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># we do an internal import here because the ssl</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># module imports the socket module</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>import</span> <span class='nam'>ssl</span> <span class='key'>as</span> <span class='nam'>_realssl</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>warnings</span><span class='op'>.</span><span class='nam'>warn</span><span class='op'>(</span><span class='str'>&quot;socket.ssl() is deprecated.&nbsp; Use ssl.wrap_socket() instead.&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>DeprecationWarning</span><span class='op'>,</span> <span class='nam'>stacklevel</span><span class='op'>=</span><span class='num'>2</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_realssl</span><span class='op'>.</span><span class='nam'>sslwrap_simple</span><span class='op'>(</span><span class='nam'>sock</span><span class='op'>,</span> <span class='nam'>keyfile</span><span class='op'>,</span> <span class='nam'>certfile</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># we need to import the same constants we used to...</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>from</span> <span class='nam'>_ssl</span> <span class='key'>import</span> <span class='nam'>SSLError</span> <span class='key'>as</span> <span class='nam'>sslerror</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>from</span> <span class='nam'>_ssl</span> <span class='key'>import</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>RAND_add</span><span class='op'>,</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>RAND_egd</span><span class='op'>,</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>RAND_status</span><span class='op'>,</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>SSL_ERROR_ZERO_RETURN</span><span class='op'>,</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>SSL_ERROR_WANT_READ</span><span class='op'>,</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>SSL_ERROR_WANT_WRITE</span><span class='op'>,</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>SSL_ERROR_WANT_X509_LOOKUP</span><span class='op'>,</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>SSL_ERROR_SYSCALL</span><span class='op'>,</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>SSL_ERROR_SSL</span><span class='op'>,</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>SSL_ERROR_WANT_CONNECT</span><span class='op'>,</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>SSL_ERROR_EOF</span><span class='op'>,</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>SSL_ERROR_INVALID_ERROR_CODE</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>import</span> <span class='nam'>os</span><span class='op'>,</span> <span class='nam'>sys</span><span class='op'>,</span> <span class='nam'>warnings</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>from</span> <span class='nam'>cStringIO</span> <span class='key'>import</span> <span class='nam'>StringIO</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>except</span> <span class='nam'>ImportError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>from</span> <span class='nam'>StringIO</span> <span class='key'>import</span> <span class='nam'>StringIO</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>from</span> <span class='nam'>errno</span> <span class='key'>import</span> <span class='nam'>EBADF</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>except</span> <span class='nam'>ImportError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>EBADF</span> <span class='op'>=</span> <span class='num'>9</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>__all__</span> <span class='op'>=</span> <span class='op'>[</span><span class='str'>&quot;getfqdn&quot;</span><span class='op'>,</span> <span class='str'>&quot;create_connection&quot;</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>__all__</span><span class='op'>.</span><span class='nam'>extend</span><span class='op'>(</span><span class='nam'>os</span><span class='op'>.</span><span class='nam'>_get_exports_list</span><span class='op'>(</span><span class='nam'>_socket</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_realsocket</span> <span class='op'>=</span> <span class='nam'>socket</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># WSA error codes</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>if</span> <span class='nam'>sys</span><span class='op'>.</span><span class='nam'>platform</span><span class='op'>.</span><span class='nam'>lower</span><span class='op'>(</span><span class='op'>)</span><span class='op'>.</span><span class='nam'>startswith</span><span class='op'>(</span><span class='str'>&quot;win&quot;</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span> <span class='op'>=</span> <span class='op'>{</span><span class='op'>}</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10004</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;The operation was interrupted.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10009</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;A bad file handle was passed.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10013</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;Permission denied.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10014</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;A fault occurred on the network??&quot;</span> <span class='com'># WSAEFAULT</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10022</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;An invalid operation was attempted.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10035</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;The socket operation would block&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10036</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;A blocking operation is already in progress.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10048</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;The network address is in use.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10054</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;The connection has been reset.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10058</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;The network has been shut down.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10060</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;The operation timed out.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10061</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;Connection refused.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10063</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;The name is too long.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10064</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;The host is down.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>errorTab</span><span class='op'>[</span><span class='num'>10065</span><span class='op'>]</span> <span class='op'>=</span> <span class='str'>&quot;The host is unreachable.&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>__all__</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='str'>&quot;errorTab&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>getfqdn</span><span class='op'>(</span><span class='nam'>name</span><span class='op'>=</span><span class='str'>&#39;&#39;</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Get fully qualified domain name from name.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; An empty argument is interpreted as meaning the local host.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; First the hostname returned by gethostbyaddr() is checked, then</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; possibly existing aliases. In case no FQDN is available, hostname</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; from gethostname() is returned.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>name</span> <span class='op'>=</span> <span class='nam'>name</span><span class='op'>.</span><span class='nam'>strip</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>name</span> <span class='key'>or</span> <span class='nam'>name</span> <span class='op'>==</span> <span class='str'>&#39;0.0.0.0&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>name</span> <span class='op'>=</span> <span class='nam'>gethostname</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>hostname</span><span class='op'>,</span> <span class='nam'>aliases</span><span class='op'>,</span> <span class='nam'>ipaddrs</span> <span class='op'>=</span> <span class='nam'>gethostbyaddr</span><span class='op'>(</span><span class='nam'>name</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>error</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>aliases</span><span class='op'>.</span><span class='nam'>insert</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='nam'>hostname</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>name</span> <span class='key'>in</span> <span class='nam'>aliases</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='str'>&#39;.&#39;</span> <span class='key'>in</span> <span class='nam'>name</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>name</span> <span class='op'>=</span> <span class='nam'>hostname</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>name</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_socketmethods</span> <span class='op'>=</span> <span class='op'>(</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;bind&#39;</span><span class='op'>,</span> <span class='str'>&#39;connect&#39;</span><span class='op'>,</span> <span class='str'>&#39;connect_ex&#39;</span><span class='op'>,</span> <span class='str'>&#39;fileno&#39;</span><span class='op'>,</span> <span class='str'>&#39;listen&#39;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;getpeername&#39;</span><span class='op'>,</span> <span class='str'>&#39;getsockname&#39;</span><span class='op'>,</span> <span class='str'>&#39;getsockopt&#39;</span><span class='op'>,</span> <span class='str'>&#39;setsockopt&#39;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;sendall&#39;</span><span class='op'>,</span> <span class='str'>&#39;setblocking&#39;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&#39;settimeout&#39;</span><span class='op'>,</span> <span class='str'>&#39;gettimeout&#39;</span><span class='op'>,</span> <span class='str'>&#39;shutdown&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>if</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>name</span> <span class='op'>==</span> <span class='str'>&quot;nt&quot;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_socketmethods</span> <span class='op'>=</span> <span class='nam'>_socketmethods</span> <span class='op'>+</span> <span class='op'>(</span><span class='str'>&#39;ioctl&#39;</span><span class='op'>,</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>if</span> <span class='nam'>sys</span><span class='op'>.</span><span class='nam'>platform</span> <span class='op'>==</span> <span class='str'>&quot;riscos&quot;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_socketmethods</span> <span class='op'>=</span> <span class='nam'>_socketmethods</span> <span class='op'>+</span> <span class='op'>(</span><span class='str'>&#39;sleeptaskw&#39;</span><span class='op'>,</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># All the method names that must be delegated to either the real socket</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># object or the _closedsocket object.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_delegate_methods</span> <span class='op'>=</span> <span class='op'>(</span><span class='str'>&quot;recv&quot;</span><span class='op'>,</span> <span class='str'>&quot;recvfrom&quot;</span><span class='op'>,</span> <span class='str'>&quot;recv_into&quot;</span><span class='op'>,</span> <span class='str'>&quot;recvfrom_into&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='str'>&quot;send&quot;</span><span class='op'>,</span> <span class='str'>&quot;sendto&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>class</span> <span class='nam'>_closedsocket</span><span class='op'>(</span><span class='nam'>object</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>__slots__</span> <span class='op'>=</span> <span class='op'>[</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_dummy</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>args</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>error</span><span class='op'>(</span><span class='nam'>EBADF</span><span class='op'>,</span> <span class='str'>&#39;Bad file descriptor&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># All _delegate_methods must also be initialized here.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>send</span> <span class='op'>=</span> <span class='nam'>recv</span> <span class='op'>=</span> <span class='nam'>recv_into</span> <span class='op'>=</span> <span class='nam'>sendto</span> <span class='op'>=</span> <span class='nam'>recvfrom</span> <span class='op'>=</span> <span class='nam'>recvfrom_into</span> <span class='op'>=</span> <span class='nam'>_dummy</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>__getattr__</span> <span class='op'>=</span> <span class='nam'>_dummy</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Wrapper around platform socket objects. This implements</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># a platform-independent dup() functionality. The</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># implementation currently relies on reference counting</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># to close the underlying socket object.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>class</span> <span class='nam'>_socketobject</span><span class='op'>(</span><span class='nam'>object</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>__doc__</span> <span class='op'>=</span> <span class='nam'>_realsocket</span><span class='op'>.</span><span class='nam'>__doc__</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>__slots__</span> <span class='op'>=</span> <span class='op'>[</span><span class='str'>&quot;_sock&quot;</span><span class='op'>,</span> <span class='str'>&quot;__weakref__&quot;</span><span class='op'>]</span> <span class='op'>+</span> <span class='nam'>list</span><span class='op'>(</span><span class='nam'>_delegate_methods</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>family</span><span class='op'>=</span><span class='nam'>AF_INET</span><span class='op'>,</span> <span class='nam'>type</span><span class='op'>=</span><span class='nam'>SOCK_STREAM</span><span class='op'>,</span> <span class='nam'>proto</span><span class='op'>=</span><span class='num'>0</span><span class='op'>,</span> <span class='nam'>_sock</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>_sock</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>_sock</span> <span class='op'>=</span> <span class='nam'>_realsocket</span><span class='op'>(</span><span class='nam'>family</span><span class='op'>,</span> <span class='nam'>type</span><span class='op'>,</span> <span class='nam'>proto</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span> <span class='op'>=</span> <span class='nam'>_sock</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>method</span> <span class='key'>in</span> <span class='nam'>_delegate_methods</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>setattr</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>method</span><span class='op'>,</span> <span class='nam'>getattr</span><span class='op'>(</span><span class='nam'>_sock</span><span class='op'>,</span> <span class='nam'>method</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>close</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span> <span class='op'>=</span> <span class='nam'>_closedsocket</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>dummy</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>_dummy</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>method</span> <span class='key'>in</span> <span class='nam'>_delegate_methods</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>setattr</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>method</span><span class='op'>,</span> <span class='nam'>dummy</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>close</span><span class='op'>.</span><span class='nam'>__doc__</span> <span class='op'>=</span> <span class='nam'>_realsocket</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>.</span><span class='nam'>__doc__</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>accept</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sock</span><span class='op'>,</span> <span class='nam'>addr</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>accept</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_socketobject</span><span class='op'>(</span><span class='nam'>_sock</span><span class='op'>=</span><span class='nam'>sock</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>addr</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>accept</span><span class='op'>.</span><span class='nam'>__doc__</span> <span class='op'>=</span> <span class='nam'>_realsocket</span><span class='op'>.</span><span class='nam'>accept</span><span class='op'>.</span><span class='nam'>__doc__</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>dup</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;dup() -&gt; socket object</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; Return a new socket object connected to the same system resource.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_socketobject</span><span class='op'>(</span><span class='nam'>_sock</span><span class='op'>=</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>makefile</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>mode</span><span class='op'>=</span><span class='str'>&#39;r&#39;</span><span class='op'>,</span> <span class='nam'>bufsize</span><span class='op'>=</span><span class='op'>-</span><span class='num'>1</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;makefile([mode[, bufsize]]) -&gt; file object</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; Return a regular file object corresponding to the socket.&nbsp; The mode</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; and bufsize arguments are as for the built-in open() function.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>_fileobject</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>,</span> <span class='nam'>mode</span><span class='op'>,</span> <span class='nam'>bufsize</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>family</span> <span class='op'>=</span> <span class='nam'>property</span><span class='op'>(</span><span class='key'>lambda</span> <span class='nam'>self</span><span class='op'>:</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>family</span><span class='op'>,</span> <span class='nam'>doc</span><span class='op'>=</span><span class='str'>&quot;the socket family&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>type</span> <span class='op'>=</span> <span class='nam'>property</span><span class='op'>(</span><span class='key'>lambda</span> <span class='nam'>self</span><span class='op'>:</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>type</span><span class='op'>,</span> <span class='nam'>doc</span><span class='op'>=</span><span class='str'>&quot;the socket type&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>proto</span> <span class='op'>=</span> <span class='nam'>property</span><span class='op'>(</span><span class='key'>lambda</span> <span class='nam'>self</span><span class='op'>:</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>proto</span><span class='op'>,</span> <span class='nam'>doc</span><span class='op'>=</span><span class='str'>&quot;the socket protocol&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>_s</span> <span class='op'>=</span> <span class='op'>(</span><span class='str'>&quot;def %s(self, *args): return self._sock.%s(*args)\n\n&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;%s.__doc__ = _realsocket.%s.__doc__\n&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>_m</span> <span class='key'>in</span> <span class='nam'>_socketmethods</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>exec</span> <span class='nam'>_s</span> <span class='op'>%</span> <span class='op'>(</span><span class='nam'>_m</span><span class='op'>,</span> <span class='nam'>_m</span><span class='op'>,</span> <span class='nam'>_m</span><span class='op'>,</span> <span class='nam'>_m</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>_m</span><span class='op'>,</span> <span class='nam'>_s</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>socket</span> <span class='op'>=</span> <span class='nam'>SocketType</span> <span class='op'>=</span> <span class='nam'>_socketobject</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>class</span> <span class='nam'>_fileobject</span><span class='op'>(</span><span class='nam'>object</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Faux file object attached to a socket object.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>default_bufsize</span> <span class='op'>=</span> <span class='num'>8192</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>name</span> <span class='op'>=</span> <span class='str'>&quot;&lt;socket&gt;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>__slots__</span> <span class='op'>=</span> <span class='op'>[</span><span class='str'>&quot;mode&quot;</span><span class='op'>,</span> <span class='str'>&quot;bufsize&quot;</span><span class='op'>,</span> <span class='str'>&quot;softspace&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='com'># &quot;closed&quot; is a property, see below</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='str'>&quot;_sock&quot;</span><span class='op'>,</span> <span class='str'>&quot;_rbufsize&quot;</span><span class='op'>,</span> <span class='str'>&quot;_wbufsize&quot;</span><span class='op'>,</span> <span class='str'>&quot;_rbuf&quot;</span><span class='op'>,</span> <span class='str'>&quot;_wbuf&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='str'>&quot;_close&quot;</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>sock</span><span class='op'>,</span> <span class='nam'>mode</span><span class='op'>=</span><span class='str'>&#39;rb&#39;</span><span class='op'>,</span> <span class='nam'>bufsize</span><span class='op'>=</span><span class='op'>-</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>close</span><span class='op'>=</span><span class='nam'>False</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span> <span class='op'>=</span> <span class='nam'>sock</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>mode</span> <span class='op'>=</span> <span class='nam'>mode</span> <span class='com'># Not actually used in this version</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>bufsize</span> <span class='op'>&lt;</span> <span class='num'>0</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>bufsize</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>default_bufsize</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bufsize</span> <span class='op'>=</span> <span class='nam'>bufsize</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>softspace</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># _rbufsize is the suggested recv buffer size.&nbsp; It is *strictly*</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># obeyed within readline() for recv calls.&nbsp; If it is larger than</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># default_bufsize it will be used for recv calls within read().</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>bufsize</span> <span class='op'>==</span> <span class='num'>0</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbufsize</span> <span class='op'>=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>bufsize</span> <span class='op'>==</span> <span class='num'>1</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbufsize</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>default_bufsize</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbufsize</span> <span class='op'>=</span> <span class='nam'>bufsize</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbufsize</span> <span class='op'>=</span> <span class='nam'>bufsize</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># We use StringIO for the read buffer to avoid holding a list</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># of variously sized string objects which have been known to</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># fragment the heap due to how they are malloc()ed and often</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># realloc()ed down much smaller than their original allocation.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span> <span class='op'>=</span> <span class='nam'>StringIO</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbuf</span> <span class='op'>=</span> <span class='op'>[</span><span class='op'>]</span> <span class='com'># A list of strings</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_close</span> <span class='op'>=</span> <span class='nam'>close</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_getclosed</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span> <span class='key'>is</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>closed</span> <span class='op'>=</span> <span class='nam'>property</span><span class='op'>(</span><span class='nam'>_getclosed</span><span class='op'>,</span> <span class='nam'>doc</span><span class='op'>=</span><span class='str'>&quot;True if the file is closed&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>close</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>flush</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_close</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__del__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># close() may fail if __init__ didn&#39;t complete</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>flush</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbuf</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buffer</span> <span class='op'>=</span> <span class='str'>&quot;&quot;</span><span class='op'>.</span><span class='nam'>join</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbuf</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbuf</span> <span class='op'>=</span> <span class='op'>[</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>sendall</span><span class='op'>(</span><span class='nam'>buffer</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>fileno</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>fileno</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>write</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>data</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>data</span> <span class='op'>=</span> <span class='nam'>str</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>)</span> <span class='com'># XXX Should really reject non-string non-buffers</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>data</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbuf</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbufsize</span> <span class='op'>==</span> <span class='num'>0</span> <span class='key'>or</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbufsize</span> <span class='op'>==</span> <span class='num'>1</span> <span class='key'>and</span> <span class='str'>&#39;\n&#39;</span> <span class='key'>in</span> <span class='nam'>data</span> <span class='key'>or</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_get_wbuf_len</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>&gt;=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbufsize</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>flush</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>writelines</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>list</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># XXX We could do better here for very long lists</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># XXX Should really reject non-string non-buffers</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbuf</span><span class='op'>.</span><span class='nam'>extend</span><span class='op'>(</span><span class='nam'>filter</span><span class='op'>(</span><span class='nam'>None</span><span class='op'>,</span> <span class='nam'>map</span><span class='op'>(</span><span class='nam'>str</span><span class='op'>,</span> <span class='nam'>list</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbufsize</span> <span class='op'>&lt;=</span> <span class='num'>1</span> <span class='key'>or</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_get_wbuf_len</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>&gt;=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbufsize</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>flush</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>_get_wbuf_len</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf_len</span> <span class='op'>=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>x</span> <span class='key'>in</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_wbuf</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf_len</span> <span class='op'>+=</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>x</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>buf_len</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>read</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>size</span><span class='op'>=</span><span class='op'>-</span><span class='num'>1</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Use max, disallow tiny reads in a loop as they are very inefficient.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># We never leave read() with any leftover data from a new recv() call</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># in our internal buffer.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>rbufsize</span> <span class='op'>=</span> <span class='nam'>max</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbufsize</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>default_bufsize</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Our use of StringIO rather than lists of string objects returned by</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># recv() minimizes memory usage and fragmentation that occurs when</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># rbufsize is large compared to the typical return value of recv().</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>seek</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>)</span>&nbsp; <span class='com'># seek end</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>size</span> <span class='op'>&lt;</span> <span class='num'>0</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Read until EOF</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span> <span class='op'>=</span> <span class='nam'>StringIO</span><span class='op'>(</span><span class='op'>)</span>&nbsp; <span class='com'># reset _rbuf.&nbsp; we consume it via buf.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>True</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>data</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>recv</span><span class='op'>(</span><span class='nam'>rbufsize</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>data</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>getvalue</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Read until size bytes or EOF seen, whichever comes first</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf_len</span> <span class='op'>=</span> <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>tell</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>buf_len</span> <span class='op'>&gt;=</span> <span class='nam'>size</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Already have size bytes in our buffer?&nbsp; Extract and return.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>seek</span><span class='op'>(</span><span class='num'>0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>rv</span> <span class='op'>=</span> <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>read</span><span class='op'>(</span><span class='nam'>size</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span> <span class='op'>=</span> <span class='nam'>StringIO</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>buf</span><span class='op'>.</span><span class='nam'>read</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>rv</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span> <span class='op'>=</span> <span class='nam'>StringIO</span><span class='op'>(</span><span class='op'>)</span>&nbsp; <span class='com'># reset _rbuf.&nbsp; we consume it via buf.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>True</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>left</span> <span class='op'>=</span> <span class='nam'>size</span> <span class='op'>-</span> <span class='nam'>buf_len</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># recv() will malloc the amount of memory given as its</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># parameter even though it often returns much less data</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># than that.&nbsp; The returned data string is short lived</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># as we copy it into a StringIO and free it.&nbsp; This avoids</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># fragmentation issues on many platforms.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>data</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>recv</span><span class='op'>(</span><span class='nam'>left</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>data</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>n</span> <span class='op'>=</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>n</span> <span class='op'>==</span> <span class='nam'>size</span> <span class='key'>and</span> <span class='key'>not</span> <span class='nam'>buf_len</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Shortcut.&nbsp; Avoid buffer data copies when:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># - We have no data in our buffer.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># AND</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># - Our call to recv returned exactly the</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#&nbsp;&nbsp; number of bytes we were asked to read.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>data</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>n</span> <span class='op'>==</span> <span class='nam'>left</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>data</span>&nbsp; <span class='com'># explicit free</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>n</span> <span class='op'>&lt;=</span> <span class='nam'>left</span><span class='op'>,</span> <span class='str'>&quot;recv(%d) returned %d bytes&quot;</span> <span class='op'>%</span> <span class='op'>(</span><span class='nam'>left</span><span class='op'>,</span> <span class='nam'>n</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf_len</span> <span class='op'>+=</span> <span class='nam'>n</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>data</span>&nbsp; <span class='com'># explicit free</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#assert buf_len == buf.tell()</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>getvalue</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>readline</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>size</span><span class='op'>=</span><span class='op'>-</span><span class='num'>1</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>seek</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>)</span>&nbsp; <span class='com'># seek end</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>tell</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>&gt;</span> <span class='num'>0</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># check if we already have it in our buffer</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>seek</span><span class='op'>(</span><span class='num'>0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>bline</span> <span class='op'>=</span> <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>readline</span><span class='op'>(</span><span class='nam'>size</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>bline</span><span class='op'>.</span><span class='nam'>endswith</span><span class='op'>(</span><span class='str'>&#39;\n&#39;</span><span class='op'>)</span> <span class='key'>or</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>bline</span><span class='op'>)</span> <span class='op'>==</span> <span class='nam'>size</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span> <span class='op'>=</span> <span class='nam'>StringIO</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>buf</span><span class='op'>.</span><span class='nam'>read</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>bline</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>bline</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>size</span> <span class='op'>&lt;</span> <span class='num'>0</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Read until \n or EOF, whichever comes first</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbufsize</span> <span class='op'>&lt;=</span> <span class='num'>1</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Speed up unbuffered case</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>seek</span><span class='op'>(</span><span class='num'>0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buffers</span> <span class='op'>=</span> <span class='op'>[</span><span class='nam'>buf</span><span class='op'>.</span><span class='nam'>read</span><span class='op'>(</span><span class='op'>)</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span> <span class='op'>=</span> <span class='nam'>StringIO</span><span class='op'>(</span><span class='op'>)</span>&nbsp; <span class='com'># reset _rbuf.&nbsp; we consume it via buf.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>data</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>recv</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>recv</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>data</span> <span class='op'>!=</span> <span class='str'>&quot;\n&quot;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>data</span> <span class='op'>=</span> <span class='nam'>recv</span><span class='op'>(</span><span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>data</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buffers</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='str'>&quot;&quot;</span><span class='op'>.</span><span class='nam'>join</span><span class='op'>(</span><span class='nam'>buffers</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>seek</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>)</span>&nbsp; <span class='com'># seek end</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span> <span class='op'>=</span> <span class='nam'>StringIO</span><span class='op'>(</span><span class='op'>)</span>&nbsp; <span class='com'># reset _rbuf.&nbsp; we consume it via buf.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>True</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>data</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>recv</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbufsize</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>data</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>nl</span> <span class='op'>=</span> <span class='nam'>data</span><span class='op'>.</span><span class='nam'>find</span><span class='op'>(</span><span class='str'>&#39;\n&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>nl</span> <span class='op'>&gt;=</span> <span class='num'>0</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>nl</span> <span class='op'>+=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>[</span><span class='op'>:</span><span class='nam'>nl</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>[</span><span class='nam'>nl</span><span class='op'>:</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>data</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>getvalue</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Read until size bytes or \n or EOF seen, whichever comes first</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>seek</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>)</span>&nbsp; <span class='com'># seek end</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf_len</span> <span class='op'>=</span> <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>tell</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>buf_len</span> <span class='op'>&gt;=</span> <span class='nam'>size</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>seek</span><span class='op'>(</span><span class='num'>0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>rv</span> <span class='op'>=</span> <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>read</span><span class='op'>(</span><span class='nam'>size</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span> <span class='op'>=</span> <span class='nam'>StringIO</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>buf</span><span class='op'>.</span><span class='nam'>read</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>rv</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span> <span class='op'>=</span> <span class='nam'>StringIO</span><span class='op'>(</span><span class='op'>)</span>&nbsp; <span class='com'># reset _rbuf.&nbsp; we consume it via buf.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>True</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>data</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_sock</span><span class='op'>.</span><span class='nam'>recv</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbufsize</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>data</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>left</span> <span class='op'>=</span> <span class='nam'>size</span> <span class='op'>-</span> <span class='nam'>buf_len</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># did we just receive a newline?</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>nl</span> <span class='op'>=</span> <span class='nam'>data</span><span class='op'>.</span><span class='nam'>find</span><span class='op'>(</span><span class='str'>&#39;\n&#39;</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='nam'>left</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>nl</span> <span class='op'>&gt;=</span> <span class='num'>0</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>nl</span> <span class='op'>+=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># save the excess data to _rbuf</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>[</span><span class='nam'>nl</span><span class='op'>:</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>buf_len</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>[</span><span class='op'>:</span><span class='nam'>nl</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Shortcut.&nbsp; Avoid data copy through buf when returning</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># a substring of our first recv().</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>data</span><span class='op'>[</span><span class='op'>:</span><span class='nam'>nl</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>n</span> <span class='op'>=</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>n</span> <span class='op'>==</span> <span class='nam'>size</span> <span class='key'>and</span> <span class='key'>not</span> <span class='nam'>buf_len</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Shortcut.&nbsp; Avoid data copy through buf when</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># returning exactly all of our first recv().</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>data</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>n</span> <span class='op'>&gt;=</span> <span class='nam'>left</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>[</span><span class='op'>:</span><span class='nam'>left</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_rbuf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>[</span><span class='nam'>left</span><span class='op'>:</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>data</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>buf_len</span> <span class='op'>+=</span> <span class='nam'>n</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#assert buf_len == buf.tell()</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>buf</span><span class='op'>.</span><span class='nam'>getvalue</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>readlines</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>sizehint</span><span class='op'>=</span><span class='num'>0</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>total</span> <span class='op'>=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>list</span> <span class='op'>=</span> <span class='op'>[</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>True</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>line</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>readline</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>line</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>list</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='nam'>line</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>total</span> <span class='op'>+=</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>line</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>sizehint</span> <span class='key'>and</span> <span class='nam'>total</span> <span class='op'>&gt;=</span> <span class='nam'>sizehint</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>list</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># Iterator protocols</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__iter__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>next</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>line</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>readline</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>line</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>StopIteration</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>line</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>_GLOBAL_DEFAULT_TIMEOUT</span> <span class='op'>=</span> <span class='nam'>object</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>create_connection</span><span class='op'>(</span><span class='nam'>address</span><span class='op'>,</span> <span class='nam'>timeout</span><span class='op'>=</span><span class='nam'>_GLOBAL_DEFAULT_TIMEOUT</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Connect to *address* and return the socket object.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Convenience function.&nbsp; Connect to *address* (a 2-tuple ``(host,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; port)``) and return the socket object.&nbsp; Passing the optional</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; *timeout* parameter will set the timeout on the socket instance</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; before attempting to connect.&nbsp; If no *timeout* is supplied, the</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; global default timeout setting returned by :func:`getdefaulttimeout`</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; is used.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>msg</span> <span class='op'>=</span> <span class='str'>&quot;getaddrinfo returns an empty list&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>host</span><span class='op'>,</span> <span class='nam'>port</span> <span class='op'>=</span> <span class='nam'>address</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>res</span> <span class='key'>in</span> <span class='nam'>getaddrinfo</span><span class='op'>(</span><span class='nam'>host</span><span class='op'>,</span> <span class='nam'>port</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='nam'>SOCK_STREAM</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>af</span><span class='op'>,</span> <span class='nam'>socktype</span><span class='op'>,</span> <span class='nam'>proto</span><span class='op'>,</span> <span class='nam'>canonname</span><span class='op'>,</span> <span class='nam'>sa</span> <span class='op'>=</span> <span class='nam'>res</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sock</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sock</span> <span class='op'>=</span> <span class='nam'>socket</span><span class='op'>(</span><span class='nam'>af</span><span class='op'>,</span> <span class='nam'>socktype</span><span class='op'>,</span> <span class='nam'>proto</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>timeout</span> <span class='key'>is</span> <span class='key'>not</span> <span class='nam'>_GLOBAL_DEFAULT_TIMEOUT</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sock</span><span class='op'>.</span><span class='nam'>settimeout</span><span class='op'>(</span><span class='nam'>timeout</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sock</span><span class='op'>.</span><span class='nam'>connect</span><span class='op'>(</span><span class='nam'>sa</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>sock</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>error</span><span class='op'>,</span> <span class='nam'>msg</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>sock</span> <span class='key'>is</span> <span class='key'>not</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sock</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>error</span><span class='op'>,</span> <span class='nam'>msg</span><span class='strut'>&nbsp;</span></p>
    
</td>
</tr>
</table>
</div>

</body>
</html>
